﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using CardDataWCFService.Contracts;

namespace CardDataWCFService
{
    // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file.
    public class CardGameService : ICardGameService
    {
        #region ICardGameService Members
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }

        public PlayerCard GetPlayerCardByRFID(String CardRFID)
        {
            return GameLogic.GetPlayerCardByRFID(CardRFID);
        }

        public List<Contracts.Player> GetPlayers()
        {
            return DataTransformer.Transform(GameLogic.GetPlayers());
        }

        public bool ShuffleDeck()
        {
            return GameLogic.ShuffleDeck();
        }

        public Contracts.Player AddPlayer(Contracts.Player player)
        {
            Contracts.Player returnPlayer = DataTransformer.Transform(GameLogic.AddPlayer(DataTransformer.Transform(player)));

            return returnPlayer;
        }

        public bool DeletePlayers()
        {
            return GameLogic.DeleteAllPlayers();
        }

        public bool DeletePlayerByName(Contracts.Player player)
        {
            throw new NotImplementedException();
        }

        public bool DeletePlayerByID(Contracts.Player player)
        {
            return GameLogic.DeletePlayerByID(DataTransformer.Transform(player));
        }

        public Contracts.PlayerCards TransferCardOwnership(CardDataWCFService.Contracts.HeldBy heldby)
        {
            HeldBy hb = DataTransformer.Transform(heldby);
            PlayerCard result = GameLogic.TransferCardOwnership(hb);
            return DataTransformer.Transform(result);
        }

        public Dictionary<Contracts.Player, List<PlayerCards>> GetCurrentTableView()
        {
            return DataTransformer.Transform(GameLogic.GetAllCardsByPlayers());
        }

        #endregion
    }
}
